package com.practice.线程池;
import java.util.concurrent.*;
/**
 * Created by IntelliJ IDEA2021.3
 * @Author: Tenghw
 * @Date: 2022/11/05  18:21
 * @Description:
 */
@SuppressWarnings("all")
public class Demo1 {
    private  static ThreadLocal<Integer> threadLocal=new ThreadLocal<>();
    private  static ExecutorService pool;
    public static void main(String[] args) throws Exception{
        threadLocal.set(10);
        try {
            pool = Executors.newFixedThreadPool(4);

            Runnable runnable1 = () -> {
                System.out.println("当前线程>>> "+Thread.currentThread().getName());
                threadLocal.set(66);
                System.out.println(threadLocal.get());
                System.out.println("~~~~~end~~~~~");
            };
            Runnable runnable2 = () -> {
                System.out.println("当前线程>>> "+Thread.currentThread().getName());
                threadLocal.set(88);
                System.out.println(threadLocal.get());
                System.out.println("~~~~~end~~~~~");
            };

            //执行任务
            pool.execute(runnable1);
            pool.execute(runnable2);
            //关闭线程池
            pool.shutdown();
        }catch (Exception e){e.printStackTrace();}
    }

}
